﻿@model Cnm.Models.ViewModels.LanguageSelectorModel
@using Cnm.Core
@using Cnm.Core.Infrastructure
@if (Model.AvailableLanguages.Count > 1)
{
    var webHelper = EngineContext.Current.Resolve<IWebHelper>();

    if (Model.UseImages)
    {
        <ul class="language-list">
            @foreach (var lang in Model.AvailableLanguages)
            {
                <li>
                    <a href="@webHelper.ModifyQueryString(Url.RouteUrl("ChangeLanguage", new { langid = lang.Id }), "returnurl=" + HttpUtility.UrlEncode(HttpContext.Current.Request.RawUrl), null)" title="@lang.Name">
                        <img title='@lang.Name' alt='@lang.Name' @(lang.Id == Model.CurrentLanguageId ? " class=selected" : null)
                             src="@Url.Content("~/Content/Images/flags/" + @lang.FlagImageFileName) " />
                    </a>
                </li>
            }
        </ul>
    }
    else
    {
        var languages = Model.AvailableLanguages.Select(lang => new SelectListItem
        {
            Text = lang.Name,
            Value = webHelper.ModifyQueryString(Url.RouteUrl("ChangeLanguage", new { langid = lang.Id }), "returnurl=" + HttpUtility.UrlEncode(HttpContext.Current.Request.RawUrl), null),
            Selected = lang.Id.Equals(Model.CurrentLanguageId)
        });

        @Html.DropDownList("customerlanguage", languages, new { onchange = "setLocation(this.value);" })
    }
}

<script>
    function setLocation(url) {
        window.location.href = url;
    }

</script>